package com.ibiaoke.system.dao;

import com.ibiaoke.common.base.BaseDao;
import com.ibiaoke.common.base.Page;
import com.ibiaoke.common.consts.CommonConsts;
import com.ibiaoke.system.entity.Floor;
import com.ibiaoke.system.entity.FloorExample;
import com.ibiaoke.system.mapper.FloorMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by Administrator on 2017/6/16.
 */
@Repository
public class FloorDao extends BaseDao<Floor, FloorExample, Integer, FloorMapper> {

    @Autowired
    private FloorMapper floorMapper;

    @Override
    public FloorMapper getMapper() {
        return floorMapper;
    }

    public int updateByFloorId(Floor floor) {
        FloorExample example = new FloorExample();
        example.createCriteria().andFloorIdEqualTo(floor.getFloorId());
        return floorMapper.updateByExampleSelective(floor, example);
    }

    public List<Floor> listFloor(Integer position, Integer status,Page page) {
        FloorExample example = new FloorExample();
        FloorExample.Criteria criteria = example.createCriteria().andDelStatusEqualTo(CommonConsts.NO);
        if (position != null) {
            criteria.andPositionEqualTo(position);
        }
        if(status != null) {
            criteria.andStatusEqualTo(status);
        }
        example.setOrderByClause("sort");

        page.setTotalCount(countByExample(example));
        example.setLimitStart(page.limitStart());
        example.setLimitEnd(page.limitEnd());

        return selectByExample(example);
    }
}
